package com.foreveross.fetl.queue;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

import javax.inject.Inject;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.foreveross.fetl.application.IFreightPriceApplication;
import com.foreveross.fetl.application.ILogMessageApplication;
import com.foreveross.fetl.application.IPlaneInfoApplication;
import com.foreveross.fetl.common.Constant;
import com.foreveross.fetl.core.domain.freight.FreightPrice;
import com.foreveross.fetl.core.domain.freight.hbase.CabinEntity;
import com.foreveross.fetl.core.domain.freight.hbase.PlaneInfoEntity;
import com.foreveross.fetl.util.DatabaseBeanUtils;
import com.foreveross.fetl.util.DateUtils;
import com.foreveross.fetl.util.RowkeyUtils;
import com.foreveross.fetl.util.StringUtils;
import com.foreveross.fetl.util.TestCommonData;
import com.foreveross.fetl.vo.LogMessageVO;

/**
 * 价差预警和竞价预警都写这了，分开的话一来建mysql和hbase表还要对应各种java类麻烦，二来只要读一次元数据表就能处理两种预警
 * 
 * @author Administrator
 */
@Component
public class PriceRatioWarning {
	private static Logger log = Logger.getLogger("PriceRatioWarning");

	@Inject private IPlaneInfoApplication planeInfoApplication;
	@Inject private IFreightPriceApplication freightPriceApplication;
	
	@Inject
	private ILogMessageApplication logMessageApplication;
	
	private int tasksNumber_ratio;//任务数 多少条rowkey
	
	private int failuresNumber_ratio;//失败数
	
	private int processNumber_ratio; //process 执行次数
	
	private int insertNumber_ratio; //插入条数 
	
	private int tasksNumber_auction;//任务数 多少条rowkey
	
	private int failuresNumber_auction;//失败数
	
	private int processNumber_auction; //process 执行次数
	
	private int insertNumber_auction; //插入条数 
	
	private long excuteStartTime_ratio;
	private long excuteStartTime_auction;
	
	private Date execute_start_ratio;
	
	private Date execute_start_auction;
	
	private LogMessageVO logMessage_ratio;
	private LogMessageVO logMessage_auction;
	
	private String taskTime_ratio=null;
	private String taskTime_auction=null;
	
	public void  ratioRollBackNumber(){
		tasksNumber_ratio=0;
		failuresNumber_ratio=0;
		processNumber_ratio=0;
		insertNumber_ratio=0;
		excuteStartTime_ratio=System.currentTimeMillis();
		LogMessageVO startLogMessage =new LogMessageVO();
		startLogMessage.setExecuteClass("PriceRatioWarning");
		startLogMessage.setExecuteName("价差预警");
		startLogMessage.setExecuteStartTime(new Date());
		startLogMessage.setExecuteType(1);
		logMessageApplication.create(startLogMessage);
		logMessage_ratio=startLogMessage;
	}
	
	public void  auctionRollBackNumber(){
		tasksNumber_auction=0;
		failuresNumber_auction=0;
		processNumber_auction=0;
		insertNumber_auction=0;
		excuteStartTime_auction=System.currentTimeMillis();
		LogMessageVO startLogMessage2 =new LogMessageVO();
		startLogMessage2.setExecuteClass("PriceRatioWarning");
		startLogMessage2.setExecuteName("竞价预警");
		startLogMessage2.setExecuteStartTime(new Date());
		startLogMessage2.setExecuteType(1);
		logMessageApplication.create(startLogMessage2);
		logMessage_auction=startLogMessage2;
	}

	public void execute() {
		try {
			Date endTime =new Date();
			Calendar c = Calendar.getInstance();
			c.add(Calendar.HOUR_OF_DAY, -1);
			taskTime_auction=DateUtils.format(c.getTime(), "yyyy-MM-dd HH");
			auctionRollBackNumber();
			taskTime_ratio=DateUtils.format(c.getTime(), "yyyy-MM-dd HH");
			ratioRollBackNumber();
			this.process(c.getTime(), endTime,new Object[]{Constant.PRICE_RATIO_WARNING,Constant.AUCTION_WARNING});
		} catch (Exception e) {
			this.saveOrUpdateLog(logMessage_auction, 3, Constant.AUCTION_WARNING, StringUtils.getStackTrace(e));
			this.saveOrUpdateLog(logMessage_ratio, 3, Constant.PRICE_RATIO_WARNING, StringUtils.getStackTrace(e));
			e.printStackTrace();
		}
	}
	
	public void manualAuctionExecute(final String start,String time){
		this.auctionRollBackNumber();
		try {
			List<String> timeList = Arrays.asList(time.split(";"));
			Calendar c = Calendar.getInstance();
			taskTime_auction=start + " " +time;
			for (String s : timeList) {
				String str =start;
				str += s;
				Date startTime = DateUtils.parse(str, "yyyyMMddHH");
				c.setTime(startTime);
				c.add(Calendar.HOUR_OF_DAY, +1);
				Date endTime = c.getTime();
				this.process(startTime, endTime, new Object[]{Constant.AUCTION_WARNING});
			}
		}catch (Exception e) {
			this.saveOrUpdateLog(logMessage_auction, 3, Constant.AUCTION_WARNING, StringUtils.getStackTrace(e));
		}
	}
	
	public void manualRatioExecute(final String start,String time){
		this.ratioRollBackNumber();
		try {
			List<String> timeList = Arrays.asList(time.split(";"));
			Calendar c = Calendar.getInstance();
			taskTime_ratio=start + " " +time;
			for (String s : timeList) {
				String str =start;
				str += s;
				Date startTime = DateUtils.parse(str, "yyyyMMddHH");
				c.setTime(startTime);
				c.add(Calendar.HOUR_OF_DAY, +1);
				Date endTime = c.getTime();
				this.process(startTime, endTime,  new Object[]{Constant.PRICE_RATIO_WARNING});
			}
		}catch (Exception e) {
			this.saveOrUpdateLog(logMessage_ratio, 3, Constant.PRICE_RATIO_WARNING, StringUtils.getStackTrace(e));
		}
	}
	

//	public static void main(String[] args) {
//		ConfigContainer.getInstance().register(DefaultPropertiesLoader.class);
//		ConfigContainer.getInstance().register(HBasePropertiesLoader.class);
//		ApplicationContext ctx = new ClassPathXmlApplicationContext(
//				"META-INF/spring/root.xml");
//		freightPriceApplication = (IFreightPriceApplication) ctx
//				.getBean("freightPriceApplication");
//		planeInfoApplication = (IPlaneInfoApplication) ctx
//				.getBean("planeInfoApplication");
//		try {
//			new PriceRatioWarning().execute();
//		} finally{
//			System.exit(0);
//		}
//		// double a = 3000.0d;
//		// double b = 1600.0d;
//		// System.out.println(b/a-1);
//	}

	public void process(Date start, Date end,Object[] types) throws Exception {
		String grabdate= DateUtils.format(start,Constant.dateFormat);
		log.info("grabdate:"+grabdate);
		String sql = "select * from fdc_alert_config where FLIGHTDATE >= sysdate() and flg_deleted=0 and ALERT_TYPE in(";
		for (int i = 0; i < types.length; i++) {
			sql += "?,";
		}
		sql = sql.substring(0,sql.length()-1)+")";
		List<Map<String, Object>> data = DatabaseBeanUtils.getMapList(sql, types);
		for (Map<String, Object> map : data) {
			String alertType = map.get("ALERT_TYPE").toString();

			String channel = (String) map.get("CARRIER_KEY");
			String flightDate = map.get("FLIGHTDATE").toString()
					.replace("-", "");
			String tocity = (String) map.get("TO_CITY");
			String fromcity = (String) map.get("FROM_CITY");
			String area = (String) map.get("AREA_CODE");
			String flightNo = (String) map.get("FLIGHTNO");

			String compareGrabChannel = (String) map.get("CONTRAST_SOURCE_KEY");
			String compareFlightNo = (String) map.get("CONTRAST_FLIGHTNO");
			if (alertType.equals(Constant.PRICE_RATIO_WARNING)) {
				processNumber_ratio++;
				if(processNumber_ratio==1){
					execute_start_ratio=new Date();
				}
				Calendar cStart = Calendar.getInstance();
				cStart.setTime(start);
				Calendar cEnd = Calendar.getInstance();
				cEnd.setTime(end); //
				// 根据航班号查航班起飞时间,用来拼rowkey
				List<Map<String, Object>> flightinfos = null;
				// 抓回来的航班信息
				try {
					flightinfos = DatabaseBeanUtils.getFlightInfo(flightNo);
					if (flightinfos != null && flightinfos.size() > 0) {
						while (cStart.before(cEnd)) {
							String startStr = DateUtils.format(
									cStart.getTime(), "yyyyMMddHH"); //
							// 抓取日期(年月日时)_渠道_区域ID_起点(使用三字码)_终点(使用三字码)_起飞时间(年月日时)_航班ID
							for (Map<String, Object> flightinfo : flightinfos) {
								tasksNumber_ratio++;
								String hour = (String) flightinfo
										.get("FLIGHT_START_TIME");
								StringBuffer startRowKey1 = new StringBuffer(
										RowkeyUtils.getRowKey(startStr,channel,  fromcity,tocity,
												flightDate + hour,flightNo,RowkeyUtils.START_ROW_KEY));
							
								StringBuffer endRowKey1 = new StringBuffer(RowkeyUtils.getRowKey(startStr,channel,  fromcity,tocity,
										flightDate + hour,flightNo,RowkeyUtils.STOP_ROW_KEY));
								
								log.info(Thread.currentThread()
												+ "  startRowkey: "
												+ startRowKey1.toString()
												+ " endRowkey:"
												+ endRowKey1.toString()); // 比较的渠道的rowkey
								StringBuffer startRowKey2 = new StringBuffer(
										RowkeyUtils.getRowKey(startStr,compareGrabChannel,  fromcity,tocity,
												flightDate + hour,flightNo,RowkeyUtils.START_ROW_KEY));
								
								StringBuffer endRowKey2 = new StringBuffer(RowkeyUtils.getRowKey(startStr,compareGrabChannel,  fromcity,tocity,
										flightDate + hour,flightNo,RowkeyUtils.START_ROW_KEY));
								
								log.info(Thread.currentThread()
												+ "  startRowkey2: "
												+ startRowKey2.toString()
												+ " endRowkey:"
												+ endRowKey2.toString());
								// 渠道 比较渠道 起点 终点 抓取时间 航班日期 航班号 比较渠道航班号 5位随机数
								// 5 5 3 3 年月日8 年月日8 8 8 5 //
								// (随机数意义在于竞价预警时设置了同一航班，不同仓位，而rowkey中木有仓位，防止hbase中数据覆盖)
								// //
								// 先查一次，避免当天第一次查的时候一个渠道有数据，但是该渠道的比较渠道没有数据
								Map<String, Object> params = new HashMap<String, Object>();
								params.put("fromCity", fromcity);
								params.put("toCity", tocity);
								params.put("flightNo", flightNo);
								params.put("flightDate", DateUtils.parse(
										flightDate, Constant.dateFormat));
								params.put("grabDate", DateUtils.parse(
										startStr.substring(0, 8),
										Constant.dateFormat));
								params.put("grabChannelKey", channel);
								params.put("compareGrabChannelKey",
										compareGrabChannel);
								params.put("type", 2);
								List<FreightPrice> freightPrices = freightPriceApplication
										.findByCondition(params); // rs
								// 和rs2只能查到抓取时间1小时的数据，可能只有一个rs有数据，
								List<PlaneInfoEntity> rs = planeInfoApplication
										.findByRowkey(startRowKey1.toString(),
												endRowKey1.toString());
								List<PlaneInfoEntity> rs2 = planeInfoApplication
										.findByRowkey(startRowKey2.toString(),
												endRowKey2.toString());
								if (freightPrices.size() != 0) {
									FreightPrice f = freightPrices.get(0);
									f.setType(2); // 如果之前存的最低价大于现在抓回来的
													// 最低价，就update
									boolean flag = Boolean.FALSE;
									if (rs.size() != 0) {
										PlaneInfoEntity p1 = rs.get(0);
										if (f.getPrice() == null
												|| f.getPrice() > p1
														.getLowerPrice()) {
											f.setFromCityName(p1.getFromCityName());
											f.setToCityName(p1.getToCityName());
											f.setPrice(p1.getLowerPrice());
											flag = Boolean.TRUE;
										}
									}
									if (rs2.size() != 0) {
										PlaneInfoEntity p2 = rs2.get(0);
										if (f.getComparePrice()==null||f.getComparePrice() > p2
												.getLowerPrice()) {
											f.setFromCityName(p2.getFromCityName());
											f.setToCityName(p2.getToCityName());
											f.setComparePrice(p2.getLowerPrice());
											flag = Boolean.TRUE;
										}
									}
									// 如果价格有变动，就要计算价差
									if (flag) {
										if (f.getComparePrice() != null
												&& f.getPrice() != null) {
											f.setPriceRatio(com.foreveross.fetl.util.StringUtils
													.getDouble(f
															.getComparePrice()
															/ f.getPrice() - 1));
										}
										freightPriceApplication.update(f);
										insertNumber_ratio++;
									}
								} else {
									FreightPrice f = new FreightPrice();
									f.setType(2); // 是否create，要满足至少一个渠道有值
									if (rs.size() != 0) {
										PlaneInfoEntity p1 = rs.get(0);
										f.setGrabDate(DateUtils.parse(p1
												.getGrabDate().substring(0, 8),
												Constant.dateFormat));
										f.setFlightDate(DateUtils
												.parse(flightDate,
														Constant.dateFormat));
										f.setFromCity(p1.getFromCity());
										f.setFromCityName(p1.getFromCityName());
										f.setToCity(p1.getToCity());
										f.setToCityName(p1.getToCityName());
										f.setGrabChannel(p1.getGrabChannel());
										f.setGrabChannelKey(channel);
										f.setPrice(p1.getLowerPrice());
										f.setFlightNo(p1.getFlightNo());
									}else {
										//当渠道没有值的时候 
										f.setFromCity(fromcity);
										f.setToCity(tocity);
										f.setFlightNo(flightNo);
										f.setFlightDate(DateUtils.parse(flightDate,
												Constant.dateFormat));
										f.setGrabDate(DateUtils.parse(grabdate, Constant.dateFormat));
										f.setGrabChannelKey(channel);
										f.setGrabChannel(TestCommonData.grabNameMap.get(channel));
									}
									if (rs2.size() != 0) {
										PlaneInfoEntity p2 = rs2.get(0);
										f.setFromCityName(p2.getFromCityName());
										f.setToCityName(p2.getToCityName());
										f.setCompareGrabChannel(p2.getGrabChannel());
										f.setCompareGrabChannelKey(compareGrabChannel);
										f.setComparePrice(p2.getLowerPrice());
									}else{
										f.setCompareGrabChannelKey(compareGrabChannel);
										f.setCompareGrabChannel(TestCommonData.grabNameMap.get(compareGrabChannel));
									}
									if (f.getComparePrice() != null
											&& f.getPrice() != null) {
										f.setPriceRatio(com.foreveross.fetl.util.StringUtils
												.getDouble(f.getComparePrice()
														/ f.getPrice() - 1));
									}
									freightPriceApplication.create(f);
									insertNumber_ratio++;
								}
							}
							cStart.add(Calendar.HOUR_OF_DAY, 1);// 开始时间加一小时 }
							log.info("end channel：" + channel);
						}
					}
				} catch (SQLException e) {
					failuresNumber_ratio++;
					e.printStackTrace();
				}
				  
			} else if (alertType.equals(Constant.AUCTION_WARNING)) {
				processNumber_auction++;
				if(processNumber_auction==1){
					execute_start_auction=new Date();
				}
				String CABIN_LEVEL = (String) map.get("CABIN_LEVEL");
				String CONTRAST_CABIN_LEVEL = (String) map
						.get("CONTRAST_CABIN_LEVEL");
				Calendar cStart = Calendar.getInstance();
				cStart.setTime(start);
				Calendar cEnd = Calendar.getInstance();
				cEnd.setTime(end);
				// 根据航班号查航班起飞时间,用来拼rowkey
				List<Map<String, Object>> flightinfos = null;
				// 抓回来的航班信息
				List<Map<String, Object>> compareFlightInfos = null;
				try {
					flightinfos = DatabaseBeanUtils.getFlightInfo(flightNo);
					// 比较渠道的航班信息
					compareFlightInfos = DatabaseBeanUtils
							.getFlightInfo(flightNo);
					List<String> startkeys = new ArrayList<String>();
					List<String> endkeys = new ArrayList<String>();
					
					List<String> compareStartkeys = new ArrayList<String>();
					List<String> compareEndkeys = new ArrayList<String>();
					if (flightinfos != null && flightinfos.size() > 0) {
						while (cStart.before(cEnd)) {
							String startStr = DateUtils.format(
									cStart.getTime(), "yyyyMMddHH");
							// 抓取日期(年月日时)_渠道_区域ID_起点(使用三字码)_终点(使用三字码)_起飞时间(年月日时)_航班ID
							for (Map<String, Object> flightinfo : flightinfos) {
								tasksNumber_auction++;
								String hour = (String) flightinfo
										.get("FLIGHT_START_TIME");
								StringBuffer startRowKey1 = new StringBuffer(
										RowkeyUtils.getRowKey(startStr,channel, fromcity,tocity,
												flightDate + hour,flightNo,RowkeyUtils.START_ROW_KEY));
							
								StringBuffer endRowKey1 = new StringBuffer(RowkeyUtils.getRowKey(startStr,channel,  fromcity,tocity,
										flightDate + hour,flightNo,RowkeyUtils.STOP_ROW_KEY));
								startkeys.add(startRowKey1.toString());
								endkeys.add(endRowKey1.toString());
								log.info(Thread.currentThread()
												+ "  startRowkey: "
												+ startRowKey1.toString()
												+ " endRowkey:"
												+ endRowKey1.toString());
							}
							for (Map<String, Object> flightinfo : compareFlightInfos) {
								// 比较的渠道的rowkey
								String hour = (String) flightinfo.get("FLIGHT_START_TIME");
								StringBuffer startRowKey2 = new StringBuffer(
										RowkeyUtils.getRowKey(startStr,compareGrabChannel,  fromcity,tocity,
												flightDate + hour,flightNo,RowkeyUtils.START_ROW_KEY));
								
								StringBuffer endRowKey2 = new StringBuffer(RowkeyUtils.getRowKey(startStr,compareGrabChannel,  fromcity,tocity,
										flightDate + hour,flightNo,RowkeyUtils.START_ROW_KEY));
								compareStartkeys.add(startRowKey2.toString());
								compareEndkeys.add(endRowKey2.toString());
								log.info(Thread.currentThread()
												+ "  startRowkey2: "
												+ startRowKey2.toString()
												+ " endRowkey:"
												+ endRowKey2.toString());
							}
							cStart.add(Calendar.HOUR_OF_DAY, 1);// 开始时间加一小时
						}
						// 渠道 比较渠道 起点 终点 抓取时间 航班日期 航班号 比较渠道航班号 5位随机数
						// 5 5 3 3 年月日8 年月日8 8 8 5
						// (随机数意义在于竞价预警时设置了同一航班，不同仓位，而rowkey中木有仓位，防止hbase中数据覆盖)
						// 先查一次，避免当天第一次查的时候一个渠道有数据，但是该渠道的比较渠道没有数据
						Map<String, Object> params = new HashMap<String, Object>();
						params.put("fromCity", fromcity);
						params.put("toCity", tocity);
						params.put("flightNo", flightNo);
						params.put("flightDate", DateUtils.parse(flightDate,
								Constant.dateFormat));
						params.put("grabDate", DateUtils.parse(grabdate, Constant.dateFormat));
						params.put("grabChannelKey", channel);
						params.put("compareGrabChannelKey", compareGrabChannel);
						params.put("compareFlightNo", compareFlightNo);
						params.put("cabinLevel", CABIN_LEVEL);
						params.put("compareCabinLevel", CONTRAST_CABIN_LEVEL);
						params.put("type", 3);
						List<FreightPrice> freightPrices = freightPriceApplication
								.findByCondition(params);
						// rs 和rs2只能查到抓取时间1小时的数据，可能只有一个rs有数据，
						
						List<PlaneInfoEntity> rs = planeInfoApplication
								.findByRowkey(startkeys,endkeys);
						List<PlaneInfoEntity> rs2 = planeInfoApplication
								.findByRowkey(compareStartkeys,compareEndkeys);
						if (freightPrices.size() != 0) {
							FreightPrice f = freightPrices.get(0);
							f.setType(3);
							// 如果之前存的最低价大于现在抓回来的 最低价，就update
							boolean flag = Boolean.FALSE;
							if (rs.size() != 0) {
								PlaneInfoEntity p1 = rs.get(0);
								if (f.getPrice() == null || f.getPrice() > p1.getLowerPrice()) {
									f.setPrice(p1.getLowerPrice());
									flag = Boolean.TRUE;
									f.setFromCityName(p1.getFromCityName());
									f.setToCityName(p1.getToCityName());
								}
							}
							if (rs2.size() != 0) {
								PlaneInfoEntity p2 = rs2.get(0);
								if (f.getComparePrice() == null || f.getComparePrice() > p2.getLowerPrice()) {
									f.setComparePrice(p2.getLowerPrice());
									flag = Boolean.TRUE;
									f.setFromCityName(p2.getFromCityName());
									f.setToCityName(p2.getToCityName());
								}
							}
							// 如果价格有变动，就要计算价差
							if (flag) {
								freightPriceApplication.update(f);
								insertNumber_auction++;
							}
						} else {
							FreightPrice f = new FreightPrice();
							f.setType(3);
							if (rs.size() != 0) {
								PlaneInfoEntity p1 = rs.get(0);
								f.setGrabDate(DateUtils.parse(p1.getGrabDate()
										.substring(0, 8), Constant.dateFormat));
								f.setFlightDate(DateUtils.parse(flightDate,
										Constant.dateFormat));
								f.setFromCity(p1.getFromCity());
								f.setFromCityName(p1.getFromCityName());
								f.setToCity(p1.getToCity());
								f.setToCityName(p1.getToCityName());
								f.setGrabChannel(p1.getGrabChannel());
								f.setGrabChannelKey(channel);
								f.setCabinLevel(CABIN_LEVEL);
								f.setPrice(getPriceByCabinLevel(p1.getCabins(),
										CABIN_LEVEL));
								f.setFlightNo(p1.getFlightNo());
							} else {
								// 要满足findByCondition查询条件。当该渠道没有数据时 要放入基本查询条件
								f.setFromCity(fromcity);
								f.setToCity(tocity);
								f.setFlightNo(flightNo);
								f.setFlightDate(DateUtils.parse(flightDate,
										Constant.dateFormat));
								f.setGrabDate(DateUtils.parse(grabdate, Constant.dateFormat));
								f.setGrabChannelKey(channel);
								f.setGrabChannel(TestCommonData.grabNameMap.get(channel));
								f.setCabinLevel(CABIN_LEVEL);
							}
							if (rs2.size() != 0) {
								PlaneInfoEntity p2 = rs2.get(0);
								f.setCompareGrabChannel(p2.getGrabChannel());
								f.setCompareGrabChannelKey(compareGrabChannel);
								f.setComparePrice(getPriceByCabinLevel(p2.getCabins(),
										CONTRAST_CABIN_LEVEL));
								f.setCompareFlightNo(p2.getFlightNo());
								f.setCompareCabinLevel(CONTRAST_CABIN_LEVEL);
							}else {
								f.setCompareGrabChannel(TestCommonData.grabNameMap.get(compareGrabChannel));
								f.setCompareGrabChannelKey(compareGrabChannel);
								f.setCompareFlightNo(compareFlightNo);
								f.setCompareCabinLevel(CONTRAST_CABIN_LEVEL);
							}
							freightPriceApplication.create(f);
							insertNumber_auction++;
							// log.info("end channel：" + channel);
						}
					}
				} catch (SQLException e) {
					failuresNumber_auction++;
					e.printStackTrace();
				}
			}
		}
		for(Object o :types){
			if(o.toString().equals(Constant.PRICE_RATIO_WARNING)){
				this.saveOrUpdateLog(logMessage_ratio, 2, Constant.PRICE_RATIO_WARNING, null);
			}
			if(o.toString().equals(Constant.AUCTION_WARNING)){
				this.saveOrUpdateLog(logMessage_auction, 2, Constant.AUCTION_WARNING, null);
			}
		}
		
		
		
		
	}

	private Double getPriceByCabinLevel(Set<CabinEntity> cbh,
			String cabinLevel) {
		for (CabinEntity cabinEntityHbase : cbh) {
			if (cabinLevel.equals(cabinEntityHbase.getProductName())) {
				return cabinEntityHbase.getPrice();
			}
		}
		return null;
	}

	private String priceReg = "\\d+.\\d+";
	private Pattern pricePattern = Pattern.compile(priceReg);
	
	private void saveOrUpdateLog(LogMessageVO vo,int executeType,String type,String result){
		LogMessageVO logMes =new LogMessageVO();
		if(null!=vo){
			logMes=logMessageApplication.getOneLogMessage(vo.getExecuteClass(), vo.getExecuteName(), vo.getExecuteStartTime(), vo.getExecuteType());
		}
		logMes.setExecuteClass("PriceRatioWarning");
		logMes.setExecuteType(executeType);
		if(result!=null){
			if(result.length()>200){
				result=result.substring(0, 199);
			}
			logMes.setResult(result);
		}
			if(type==Constant.PRICE_RATIO_WARNING){
				logMes.setExecuteName("价差预警");
				logMes.setExecuteStartTime(execute_start_ratio);
				logMes.setExecuteEndTime(new Date());
				logMes.setFailuresNumber(failuresNumber_ratio);
				logMes.setTasksNumber(tasksNumber_ratio);
				logMes.setInsertNumber(insertNumber_ratio);
				logMes.setTaskTime(taskTime_ratio);
				logMes.setExecuteTotalTime(System.currentTimeMillis()-excuteStartTime_ratio);
			}
			if(type==Constant.AUCTION_WARNING){
				logMes.setExecuteClass("PriceRatioWarning");
				logMes.setExecuteName("竞价预警");
				logMes.setExecuteStartTime(execute_start_auction);
				logMes.setExecuteEndTime(new Date());
				logMes.setFailuresNumber(failuresNumber_auction);
				logMes.setTasksNumber(tasksNumber_auction);
				logMes.setInsertNumber(insertNumber_auction);
				logMes.setTaskTime(taskTime_auction);
				logMes.setExecuteTotalTime(System.currentTimeMillis()-excuteStartTime_auction);
			}
			if(logMes.getId()!=null && logMes.getId()!=0){
				logMessageApplication.update(logMes);
			}else{
				logMessageApplication.create(logMes);
			}
	}

//	private void a() {
//		 
//		 
//	}
}
